<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <link rel="Shortcut Icon" href="../images/aecc.ico" type="image/x-icon" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="../StaticFiles/element-ui/element-ui.css">
  <link rel="stylesheet" href="../StaticFiles/nprogress/nprogress.min.css">
  <link rel="stylesheet" href="../styles/vue-page-common.css">
  <script src="../Scripts/vue.min.js"></script>
  <script src="../StaticFiles/element-ui/element-ui.js"></script>
  <script src="../Scripts/axios.min.js"></script>
  <script src="../StaticFiles/nprogress/nprogress.min.js"></script>
  <script src="../Scripts/dayjs.min.js"></script>
  <script src="../Scripts/axios.config.js"></script>
  <title>热表转工报表(生产部考核)</title>
  <style>
    .el-select .el-tag {
      display: inline-block;
    }

    .compute-info-zone .el-form-item {
      margin-bottom: 5px !important;
    }

    .el-date-editor--daterange.el-input,
    .el-date-editor--daterange.el-input__inner,
    .el-date-editor--timerange.el-input,
    .el-date-editor--timerange.el-input__inner {
      width: 300px;
    }
  </style>
</head>

<body>
  <div id="app" v-cloak v-on:keyup.enter="getData">
    <!-- 报表标题 -->
    <vue2-report-header :title="'热表转工报表'"></vue2-report-header>
    <div style="padding: 10px;">
      <!-- 汇总显示区域 -->
      <el-form class="compute-info-zone" :inline="true" :label-position="'left'">
        <el-tooltip effect="dark" placement="top-start">
          <div slot="content">
            <p>排产总数统计规则:</p>
            <p>排产时间在【机加排产时间】所选范围内的排产工序数。</p>
          </div>
          <el-form-item label="排产总数:">
            <el-tag>{{computeData.total}}项</el-tag>
          </el-form-item>
        </el-tooltip>

        <el-tooltip effect="dark" placement="top-start">
          <div slot="content">
            <p>准时到达统计规则:</p>
            <p>在【有效排产】的数据中筛选: 热表接收时间 - 计划发出时间 = 0，或 热表接收时间 - 计划发出时间 = -1。</p>
          </div>
          <el-form-item label="准时到达:">
            <el-tag type="success">{{computeData.intime}}项</el-tag>
          </el-form-item>
        </el-tooltip>

        <el-tooltip effect="dark" placement="top-start">
          <div slot="content">
            <p>未准时到达统计规则:</p>
            <p>在【有效排产】里排除 【准时到达】</p>
          </div>
          <el-form-item label="未准时到达:">
            <el-tag type="danger">{{computeData.notintime}}项</el-tag>
          </el-form-item>
        </el-tooltip>

        <el-tooltip effect="dark" placement="top-start">
          <div slot="content">
            <p>准时到达率计算规则:</p>
            <p>准时到达率 = (准时到达 / 有效排产) * 100%</p>
          </div>
          <el-form-item label="准时到达率:">
            <el-tag type="success">{{computeData.intimeRate}}%</el-tag>
          </el-form-item>
        </el-tooltip>

        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="getCompute">计算排产率</el-button>
          <el-button type="primary" icon="el-icon-download" size="mini" @click="getExportExcel('exportPlanRate')">排产率明细
          </el-button>
          <!-- <el-button type="warning" icon="el-icon-download" size="mini" @click="getExportExcel('exportPlanTemp')">
            排产临时项明细</el-button> -->
          <el-button type="danger" icon="el-icon-download" size="mini" @click="getExportExcel('exportNoIntime')">
            未准时到达项明细</el-button>
        </el-form-item>
      </el-form>

      <!-- 查询条件区 -->
      <el-form class="query-zone" :inline="true" :model="queryInfo" :rules="rules" ref="queryInfoRef"
        :label-position="'left'">

        <el-form-item label="主制分厂:" prop="originalfactoryid">
          <el-select v-model="queryInfo.originalfactoryid" placeholder="请选择主制分厂" clearable filterable>
            <el-option v-for="f in factoryList" :key="f.factoryid" :label="f.factoryname" :value="f.factoryid">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="承制分厂:">
          <el-select v-model="queryInfo.tofactoryname" placeholder="请选择主制分厂" @change="selectChange">
            <el-option v-for="f in factoryList" :key="f.factoryname" :label="f.factoryname" :value="f.factoryname">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item prop='productname' label="零件图号:">
          <el-autocomplete v-model.trim="queryInfo.productname" placeholder="请输入零件图号" :trigger-on-focus="false"
            style="width:240px;" :fetch-suggestions="searchProductAsync" :value-key="'productname'" :debounce="500">
          </el-autocomplete>
        </el-form-item>

        <el-form-item prop='containername' label="流水卡号:">
          <el-autocomplete v-model.trim="queryInfo.containername" placeholder="请输入流水卡号" :trigger-on-focus="false"
            style="width:240px;" :fetch-suggestions="searchContainerAsync" :value-key="'containername'" :debounce="500">
          </el-autocomplete>
        </el-form-item>

        <el-form-item prop="receivepersonid" label="接收人:">
          <el-select v-model="queryInfo.receivepersonid" placeholder="请选择接收人" clearable filterable>
            <el-option v-for="p in diaoDuYuanList" :key="p.employeeid" :label="p.fullname" :value="p.employeeid">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item prop="receivedate" label="接收时间:">
          <el-date-picker v-model="queryInfo.receivedate" type="daterange" range-separator="至" value-format="yyyy-MM-dd"
            start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions"></el-date-picker>
        </el-form-item>

        <el-form-item prop="status" label="转工状态:">
          <el-select v-model="queryInfo.status" placeholder="请选择转工状态" clearable filterable>
            <el-option v-for="s in statusList" :key="s.status" :label="s.status" :value="s.status">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item prop="plannedstartdate" label="计划发出时间:" v-show="isShow">
          <el-date-picker v-model="queryInfo.plannedstartdate" type="daterange" range-separator="至"
            value-format="yyyy-MM-dd" start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions">
          </el-date-picker>
        </el-form-item>

        <el-form-item style="height:40px;">
          <el-button type="primary" icon="el-icon-search" size="mini" @click="getData">查询</el-button>
          <el-button type="primary" icon="el-icon-download" size="mini" @click="getExportExcel('exportExcel')">导出
          </el-button>
        </el-form-item>
      </el-form>

      <!-- 表格显示区 -->
      <el-table class="table-date-zone" v-loading="loading" v-loading.fullscreen.lock="loading"
        :element-loading-text="loadingText" element-loading-background="rgba(0,0,0,0.8)" :data="dataList" stripe border
        show-overflow-tooltip>
        <el-table-column type="index" width="40"></el-table-column>
        <el-table-column label="主制分厂" prop="factoryname" width="100" show-overflow-tooltip></el-table-column>
        <el-table-column label="零件图号" prop="productname" width="140" show-overflow-tooltip></el-table-column>
        <el-table-column label="零件名称" prop="productdescription" width="100" show-overflow-tooltip></el-table-column>
        <el-table-column label="流水卡号" prop="containername" show-overflow-tooltip></el-table-column>
        <el-table-column label="热表批次号" prop="rbcontainername" width="200" show-overflow-tooltip></el-table-column>
        <el-table-column label="当前工序" prop="currentspec" show-overflow-tooltip width="120"></el-table-column>
        <el-table-column label="当前在制工艺路线" prop="workflowname" show-overflow-tooltip width="100"></el-table-column>
        <el-table-column label="当前在制工艺版本" prop="workflowrevision" show-overflow-tooltip width="80"></el-table-column>
        <el-table-column label="数量" prop="qty" width="60"></el-table-column>
        <el-table-column label="排产工艺路线" prop="pworkflowname" show-overflow-tooltip width="100"></el-table-column>
        <el-table-column label="排产工艺版本" prop="pworkflowrevision" show-overflow-tooltip width="80"></el-table-column>
        <el-table-column label="转工工序" prop="workflowstepname" width="120" show-overflow-tooltip></el-table-column>
        <el-table-column label="接收人" prop="receiver" width="80"></el-table-column>
        <el-table-column label="接收时间" prop="recivedate" width="100" :formatter="splitDate"></el-table-column>
        <el-table-column label="转工状态" width="80">
          <template slot-scope="scope">
            {{scope.row.status}}
          </template>
        </el-table-column>
        <el-table-column label="机加排产时间" prop="stepplancreatedate" width="100" :formatter="splitDate"></el-table-column>
        <el-table-column label="承制分厂排产时间" prop="stepplanshipdate" width="100" :formatter="splitDate"></el-table-column>
        <el-table-column label="机加排产人" prop="jjplaner" width="90"></el-table-column>
        <el-table-column label="排产状态" width="80">
          <template slot-scope="scope">
            <div v-if='scope.row.planstatus === "未排产"'>
              <el-tag type='danger'>未排产</el-tag>
            </div>
            <div v-else>
              <el-tag type="success">已排产</el-tag>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="热表是否派工" width="80">
          <template slot-scope="scope">
            <div v-if='scope.row.dispatchstatus === "已派工"'>
              <el-tag type='success'>已派工</el-tag>
            </div>
            <div v-else>
              <el-tag type="danger">未派工</el-tag>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="其他信息" width="80" type="expand">
          <template slot-scope="props">
            <el-descriptions title="其他转工信息" direction="vertical" border :column="8" :contentStyle="{'height':'30px'}"
              style="padding:10px;">
              <el-descriptions-item>
                <template slot="label">
                  <i class="el-icon-user-solid"></i> 承制分厂排产人
                </template>
                {{props.row.rbplaner}}
              </el-descriptions-item>
              <el-descriptions-item>
                <template slot="label">
                  <i class="el-icon-user-tickets"></i> 责任工区
                </template>
                {{props.row.fromworkcentername}}
              </el-descriptions-item>
              <el-descriptions-item>
                <template slot="label">
                  <el-popover placement="top-start" title="计划发出时间" width="300" trigger="hover"
                    content="机加分厂在转工排产时填写的时间">
                    <i class="el-icon-info" slot="reference"></i>
                  </el-popover>
                  计划发出时间
                </template>
                <span v-if="props.row.plannedstartdate">{{props.row.plannedstartdate.split('T')[0]}}</span>
              </el-descriptions-item>
              <el-descriptions-item>
                <template slot="label">
                  <el-popover placement="top-start" title="计划完成时间" width="300" trigger="hover"
                    content="承制分厂在转工排产时填写的时间">
                    <i class="el-icon-info" slot="reference"></i>
                  </el-popover>
                  计划完成时间
                </template>
                <span v-if="props.row.plannedfinishdate">{{props.row.plannedfinishdate.split('T')[0]}}</span>
              </el-descriptions-item>
              <el-descriptions-item>
                <template slot="label">
                  <el-popover placement="top-start" title="要求完成时间" width="300" trigger="hover"
                    content="机加分厂在转工转出时需要填写的时间">
                    <i class="el-icon-info" slot="reference"></i>
                  </el-popover>
                  要求完成时间
                </template>
                <span v-if="props.row.needcompletedate">{{props.row.needcompletedate.split('T')[0]}}</span>
              </el-descriptions-item>
              <el-descriptions-item>
                <template slot="label">
                  <el-popover placement="top-start" title="实际发出时间" width="300" trigger="hover" content="机加分厂实际转工转出的时间">
                    <i class="el-icon-info" slot="reference"></i>
                  </el-popover>
                  实际发出时间
                </template>
                <span v-if="props.row.senddate">{{props.row.senddate.split('T')[0]}}</span>
              </el-descriptions-item>
              <el-descriptions-item>
                <template slot="label">
                  <el-popover placement="top-start" title="预计完成时间" width="300" trigger="hover"
                    content="承制分厂在转工接收时需要填写的时间">
                    <i class="el-icon-info" slot="reference"></i>
                  </el-popover>
                  预计完成时间
                </template>
                <span v-if="props.row.estimatedcompletedate">{{props.row.estimatedcompletedate.split('T')[0]}}</span>
              </el-descriptions-item>
              <el-descriptions-item>
                <template slot="label">
                  <el-popover placement="top-start" title="完成时间" width="300" trigger="hover" content="承制分厂转工实际完成的时间">
                    <i class="el-icon-info" slot="reference"></i>
                  </el-popover>
                  完成时间
                </template>
                <span v-if="props.row.completedate">{{props.row.completedate.split('T')[0]}}</span>
              </el-descriptions-item>
              <el-descriptions-item>
                <template slot="label">
                  <el-popover placement="top-start" title="转入时间" width="300" trigger="hover" content="机加分厂转回到本分厂的时间">
                    <i class="el-icon-info" slot="reference"></i>
                  </el-popover>
                  转入时间
                </template>
                <span v-if="props.row.shipindate">{{props.row.shipindate.split('T')[0]}}</span>
              </el-descriptions-item>
              <el-descriptions-item label-class-name="red" content-class-name="red">
                <template slot="label">
                  <el-popover placement="top-start" title="拒收时间" width="300" trigger="hover" content="承制分厂拒绝接收的时间">
                    <i class="el-icon-info" slot="reference"></i>
                  </el-popover>
                  拒收时间
                </template>
                <span v-if="props.row.denydate">{{props.row.denydate.split('T')[0]}}</span>
              </el-descriptions-item>
              <el-descriptions-item label-class-name="red" content-class-name="red">
                <template slot="label">
                  <i class="el-icon-user-solid"></i> 拒收人
                </template>
                {{props.row.denyer}}
              </el-descriptions-item>
              <el-descriptions-item label-class-name="red" content-class-name="red">
                <template slot="label">
                  <i class="el-icon-tickets"></i> 拒收原因
                </template>
                {{props.row.denyreason}}
              </el-descriptions-item>
              <el-descriptions-item label-class-name="red" content-class-name="red">
                <template slot="label">
                  <el-popover placement="top-start" title="完成超期时间" width="300" trigger="hover"
                    content="若承制分厂已完成，完成超期时间 = 完成时间 - 要求完成日期。若承制分厂未完成，完成超期时间 = 当前时间 - 要求完成时间。">
                    <i class="el-icon-info" slot="reference"></i>
                  </el-popover>
                  完成超期时间
                </template>
                {{props.row.delay}}
              </el-descriptions-item>
              <el-descriptions-item label-class-name="red" content-class-name="red">
                <template slot="label">
                  <el-popover placement="top-start" title="发出超期时间" width="300" trigger="hover"
                    content="发出超期时间 = 接收时间 - 计划发出时间">
                    <i class="el-icon-info" slot="reference"></i>
                  </el-popover>
                  发出超期时间
                </template>
                {{props.row.fccq}}
              </el-descriptions-item>
              <el-descriptions-item>
                <template slot="label">
                  <el-popover placement="top-start" title="发出提前时间" width="300" trigger="hover"
                    content="发出提前时间 = 计划发出时间 - 接收时间">
                    <i class="el-icon-info" slot="reference"></i>
                  </el-popover>
                  发出提前时间
                </template>
                {{props.row.fctq}}
              </el-descriptions-item>
            </el-descriptions>
          </template>
        </el-table-column>
      </el-table>

      <!-- 分页组件 -->
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
        :current-page="queryInfo.currentPage" :page-sizes="[10,20,50]" :page-size="queryInfo.pageSize"
        layout="prev,pager,next,jumper,sizes,total" :total="total">
      </el-pagination>

      <!-- 回到顶部 -->
      <el-backtop></el-backtop>

      <!-- 各分厂排产率统计 -->
      <el-dialog title="各分厂排产率情况" :width="'95%'" :top="'40px'" :visible.sync="chartDialogVisiable"
        @opened="chartDialogOpened">
        <div id="chart" style="width:100%;height:700px;"></div>
      </el-dialog>

      <!-- 各分厂排产率统计明细 -->
      <el-dialog :title="detail.title" :width="'95%'" :top="'0px'" :visible.sync="detail.dialogVisiable">
        <el-table v-loading="loading" v-loading.fullscreen.lock="loading" :element-loading-text="loadingText"
          element-loading-background="rgba(0,0,0,0.8)" :data="detail.dataList" stripe border>
          <el-table-column type="index" width="40"></el-table-column>
          <el-table-column label="主制分厂" prop="factoryname" width="120" show-overflow-tooltip></el-table-column>
          <el-table-column label="零件图号" prop="productname" width="140" show-overflow-tooltip></el-table-column>
          <el-table-column label="零件名称" prop="productdescription" width="100" show-overflow-tooltip></el-table-column>
          <el-table-column label="流水卡号" prop="containername" show-overflow-tooltip></el-table-column>
          <el-table-column label="当前工序" prop="currentspec" show-overflow-tooltip width="120"></el-table-column>
          <el-table-column label="数量" prop="qty" width="60"></el-table-column>
          <el-table-column label="转工工序" prop="workflowstepname" width="120" show-overflow-tooltip></el-table-column>
          <el-table-column label="接收人" prop="receiver" width="80"></el-table-column>
          <el-table-column label="接收时间" prop="recivedate" width="100" :formatter="splitDate"></el-table-column>
          <el-table-column label="转工状态" width="80">
            <template slot-scope="scope">
              {{scope.row.status}}
            </template>
          </el-table-column>
          <el-table-column label="机加排产时间" prop="stepplancreatedate" width="100" :formatter="splitDate">
          </el-table-column>
          <el-table-column label="承制分厂排产时间" prop="stepplanshipdate" width="100" :formatter="splitDate">
          </el-table-column>
          <el-table-column label=" 机加排产人" prop="jjplaner" width="90"></el-table-column>
          <el-table-column label="排产状态" width="80">
            <template slot-scope="scope">
              <div v-if='scope.row.planstatus === "未排产"'>
                <el-tag type='danger'>未排产</el-tag>
              </div>
              <div v-else>
                <el-tag type="success">已排产</el-tag>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="其他信息" width="80" type="expand">
            <template slot-scope="props">
              <el-descriptions title="其他转工信息" direction="vertical" border :column="8" :contentStyle="{'height':'30px'}"
                style="padding:10px;">
                <el-descriptions-item>
                  <template slot="label">
                    <i class="el-icon-user-solid"></i> 承制分厂排产人
                  </template>
                  {{props.row.rbplaner}}
                </el-descriptions-item>
                <el-descriptions-item>
                  <template slot="label">
                    <i class="el-icon-user-tickets"></i> 责任工区
                  </template>
                  {{props.row.fromworkcentername}}
                </el-descriptions-item>
                <el-descriptions-item>
                  <template slot="label">
                    <el-popover placement="top-start" title="计划发出时间" width="300" trigger="hover"
                      content="机加分厂在转工排产时填写的时间">
                      <i class="el-icon-info" slot="reference"></i>
                    </el-popover>
                    计划发出时间
                  </template>
                  <span v-if="props.row.plannedstartdate">{{props.row.plannedstartdate.split('T')[0]}}</span>
                </el-descriptions-item>
                <el-descriptions-item>
                  <template slot="label">
                    <el-popover placement="top-start" title="计划完成时间" width="300" trigger="hover"
                      content="承制分厂在转工排产时填写的时间">
                      <i class="el-icon-info" slot="reference"></i>
                    </el-popover>
                    计划完成时间
                  </template>
                  <span v-if="props.row.plannedfinishdate">{{props.row.plannedfinishdate.split('T')[0]}}</span>
                </el-descriptions-item>
                <el-descriptions-item>
                  <template slot="label">
                    <el-popover placement="top-start" title="要求完成时间" width="300" trigger="hover"
                      content="机加分厂在转工转出时需要填写的时间">
                      <i class="el-icon-info" slot="reference"></i>
                    </el-popover>
                    要求完成时间
                  </template>
                  <span v-if="props.row.needcompletedate">{{props.row.needcompletedate.split('T')[0]}}</span>
                </el-descriptions-item>
                <el-descriptions-item>
                  <template slot="label">
                    <el-popover placement="top-start" title="实际发出时间" width="300" trigger="hover"
                      content="机加分厂实际转工转出的时间">
                      <i class="el-icon-info" slot="reference"></i>
                    </el-popover>
                    实际发出时间
                  </template>
                  <span v-if="props.row.senddate">{{props.row.senddate.split('T')[0]}}</span>
                </el-descriptions-item>
                <el-descriptions-item>
                  <template slot="label">
                    <el-popover placement="top-start" title="预计完成时间" width="300" trigger="hover"
                      content="承制分厂在转工接收时需要填写的时间">
                      <i class="el-icon-info" slot="reference"></i>
                    </el-popover>
                    预计完成时间
                  </template>
                  <span v-if="props.row.estimatedcompletedate">{{props.row.estimatedcompletedate.split('T')[0]}}</span>
                </el-descriptions-item>
                <el-descriptions-item>
                  <template slot="label">
                    <el-popover placement="top-start" title="完成时间" width="300" trigger="hover" content="承制分厂转工实际完成的时间">
                      <i class="el-icon-info" slot="reference"></i>
                    </el-popover>
                    完成时间
                  </template>
                  <span v-if="props.row.completedate">{{props.row.completedate.split('T')[0]}}</span>
                </el-descriptions-item>
                <el-descriptions-item>
                  <template slot="label">
                    <el-popover placement="top-start" title="转入时间" width="300" trigger="hover" content="机加分厂转回到本分厂的时间">
                      <i class="el-icon-info" slot="reference"></i>
                    </el-popover>
                    转入时间
                  </template>
                  <span v-if="props.row.shipindate">{{props.row.shipindate.split('T')[0]}}</span>
                </el-descriptions-item>
                <el-descriptions-item label-class-name="red" content-class-name="red">
                  <template slot="label">
                    <el-popover placement="top-start" title="拒收时间" width="300" trigger="hover" content="承制分厂拒绝接收的时间">
                      <i class="el-icon-info" slot="reference"></i>
                    </el-popover>
                    拒收时间
                  </template>
                  <span v-if="props.row.denydate">{{props.row.denydate.split('T')[0]}}</span>
                </el-descriptions-item>
                <el-descriptions-item label-class-name="red" content-class-name="red">
                  <template slot="label">
                    <i class="el-icon-user-solid"></i> 拒收人
                  </template>
                  {{props.row.denyer}}
                </el-descriptions-item>
                <el-descriptions-item label-class-name="red" content-class-name="red">
                  <template slot="label">
                    <i class="el-icon-tickets"></i> 拒收原因
                  </template>
                  {{props.row.denyreason}}
                </el-descriptions-item>
                <el-descriptions-item label-class-name="red" content-class-name="red">
                  <template slot="label">
                    <el-popover placement="top-start" title="完成超期时间" width="300" trigger="hover"
                      content="若承制分厂已完成，完成超期时间 = 完成时间 - 要求完成日期。若承制分厂未完成，完成超期时间 = 当前时间 - 要求完成时间。">
                      <i class="el-icon-info" slot="reference"></i>
                    </el-popover>
                    完成超期时间
                  </template>
                  {{props.row.delay}}
                </el-descriptions-item>
                <el-descriptions-item label-class-name="red" content-class-name="red">
                  <template slot="label">
                    <el-popover placement="top-start" title="发出超期时间" width="300" trigger="hover"
                      content="发出超期时间 = 接收时间 - 计划发出时间">
                      <i class="el-icon-info" slot="reference"></i>
                    </el-popover>
                    发出超期时间
                  </template>
                  {{props.row.fccq}}
                </el-descriptions-item>
                <el-descriptions-item>
                  <template slot="label">
                    <el-popover placement="top-start" title="发出提前时间" width="300" trigger="hover"
                      content="发出提前时间 = 计划发出时间 - 接收时间">
                      <i class="el-icon-info" slot="reference"></i>
                    </el-popover>
                    发出提前时间
                  </template>
                  {{props.row.fctq}}
                </el-descriptions-item>
              </el-descriptions>
            </template>
          </el-table-column>
        </el-table>
        <!-- 分页 -->
        <el-pagination @current-change="handleDetailCurrentChange" :current-page="detail.queryInfo.currentPage"
          :page-sizes="[detail.queryInfo.pageSize]" :page-size="detail.queryInfo.pageSize"
          layout="prev,pager,next,jumper,sizes,total" :total="detail.total">
        </el-pagination>
      </el-dialog>
    </div>
  </div>

  <script src="../Scripts/echarts/echarts-5.4.0.min.js"></script>
  <script type="module">
    import { fetchSuggestion, exportExcelData } from '../Scripts/hooks/useCommonMethod.js'
    import { getFactory, getProductFamily, getFactoryUsersByRoleName } from '../Scripts/hooks/fetchAPI.js'
    import { barOption, colorList } from '../Scripts/hooks/chartConfig.js'
    import { prevWeek, thisWeek, nextWeek, prevMonth, thisMonth, nextMonth } from '../Scripts/hooks/useDateShortCut.js'
    import { splitDate } from '../Scripts/hooks/format.js'
    import Vue2ReportHeader from '../Scripts/components/Vue2ReportHeader.js';
    const app = new Vue({
      el: '#app',
      components: { Vue2ReportHeader },
      data: {
        splitDate,
        loading: false,
        loadingText: '数据加载中...',
        fullscreenLoading: false,
        total: 0,
        factoryList: [],
        productfamilyList: [],//机型
        diaoDuYuanList: [],//接收人(调度员)
        statusList: [
          { status: '未转出' },
          { status: '待接收' },
          { status: '待完成' },
          { status: '待转入' },
          { status: '已转入' },
          { status: '转工拒收' }
        ],
        queryInfo: {
          tofactoryname: '热表厂',
          originalfactoryid: '',//主制分厂
          productname: '',//零件图号
          containername: '',//流水卡号
          status: '',//转工状态
          receiver: '',//接收人
          receivedate: '',//接收日期
          // stepplancreatedate: '',//机加排产日期
          plannedstartdate: '',// 计划发出日期
          // thursday: '', // 指定排产节点（周四）
          currentPage: 1,//当前页
          pageSize: 10//每页显示条数
        },
        dataList: [],
        computeData: {
          total: '', //总数
          valid: '', //有效排产
          invalid: '', //排产临时项
          intime: '', // 准时到达
          notintime: '', // 未准时到达项
          planRate: '', //排产率
          intimeRate: '' // 准时到达率
        },
        chartDialogVisiable: false,
        detail: {
          dialogVisiable: false,
          queryInfo: { factoryname: '', title: '', currentPage: 1, pageSize: 16 },
          dataList: [], total: 0, title: ''
        },
        // 表单验证
        rules: {
          thursday: [{ required: true, message: '此必填项不能为空', trigger: 'change' }],
          stepplancreatedate: [{ required: true, message: '此必填项不能为空', trigger: 'change' }],
          plannedstartdate: [{ required: true, message: '此必填项不能为空', trigger: 'change' }]
        },
        isShow: true,
        pickerOptions: { shortcuts: [prevWeek, thisWeek, nextWeek, prevMonth, thisMonth, nextMonth] },
        baseApi: '../handler/report/RbContainerShipRecordReport.ashx',
      },
      methods: {
        // 查询件号
        searchProductAsync(value, callback) {
          fetchSuggestion({ actionName: 'getProductnameAsync', name: 'productname', value, callback })
        },
        // 查询批次号
        searchContainerAsync(value, callback) {
          fetchSuggestion({ actionName: 'getContainernameAsync', name: 'containername', value, callback })
        },
        //查询数据
        async getData() {
          this.$refs['queryInfoRef'].validate(async (valid) => {
            if (!valid) {
              return this.$message.error('必填项不能为空');
            }
            this.loading = true;
            this.loadingText = '数据加载中...';
            const { data: { data, meta, total } } = await axios({
              url: `${this.baseApi}?action=getData`,
              method: 'post',
              data: { type: 'getData', ...this.queryInfo }
            })
            this.loading = false;
            if (meta.status === 500) { return this.$message.error(meta.msg); }
            this.dataList = data;
            this.total = total;
          })
        },
        // 计算排产率
        async getCompute() {
          this.$refs['queryInfoRef'].validate(async (valid) => {
            if (!valid) {
              return this.$message.error('必填项不能为空');
            }
            this.chartDialogVisiable = true;
            this.loading = true;
            this.loadingText = '数据加载中...';
            const { data: { data, meta, total } } = await axios({
              url: `${this.baseApi}?action=getCompute`,
              method: 'post',
              data: { type: 'getCompute', ...this.queryInfo }
            })
            this.loading = false;
            if (meta.status === 500) { return this.$message.error(meta.msg); }
            this.computeData.total = data[0]["total"];
            this.computeData.valid = data[0]["valid"];
            this.computeData.invalid = data[0]["invalid"];
            this.computeData.intime = data[0]["intime"];
            this.computeData.notintime = data[0]["notintime"];
            this.computeData.planRate = data[0]["plan-rate"];
            this.computeData.intimeRate = data[0]["intime-rate"];
          })
        },
        async selectChange(factoryname) {
          this.queryInfo.receivepersonid = null;
          if (factoryname) {
            this.diaoDuYuanList = await getFactoryUsersByRoleName({ factoryname, rolename: '调度员' });
          }
        },
        handleCurrentChange(newPage) {
          this.queryInfo.currentPage = newPage;
          this.getData();
        },
        handleSizeChange(newSize) {
          this.queryInfo.pageSize = newSize;
          this.getData();
        },
        // 导出excel
        async getExportExcel(actionName) {
          const config = {
            url: `${this.baseApi}?action=${actionName}`,
            data: { type: actionName, ...this.queryInfo }
          }
          exportExcelData(config, this);
        },
        // 排产率对话框打开时
        async chartDialogOpened() {
          echarts.dispose(document.getElementById("chart"));
          let chart = echarts.init(document.getElementById('chart'));
          chart.showLoading({
            text: '数据查询中...',
            effect: 'whirling',
            maskColor: 'transparent',
            textColor: '#000',
            color: '#66b1ff'
          })
          const { data: { data, meta } } = await axios({
            url: `${this.baseApi}?action=getChart`,
            method: 'post',
            data: { type: 'getChart', ...this.queryInfo }
          })
          chart.hideLoading();
          if (meta.status === 500) { return this.$message.error(meta.msg); }
          if (data.length === 0) { return; }

          echarts.dispose(document.getElementById("chart"));
          chart = echarts.init(document.getElementById('chart'));

          let arrFactoryname = [], arrValid = [], arrIntime = [], arrNotintime = [], arrIntimeRate = [];
          for (const i of data) {
            arrFactoryname.push(i.factoryname);
            arrValid.push(i.valid);
            arrIntime.push(i.intime);
            arrNotintime.push(i.notintime);
            arrIntimeRate.push(i.intimerate);
          }

          let option = barOption({ themeColor: 'dark' });
          option.legend.data = ['计划发出项', '准时到达项', '未准时到达项', '准时到达率'];
          option.xAxis.data = arrFactoryname;

          option.series[0] = _.merge(option.series[0], {
            name: '计划发出项',
            data: arrValid,
            label: { color: colorList.blue.color },
            itemStyle: { color: { colorStops: colorList.blue.colorStops } }
          });

          option.series[1] = _.merge(_.cloneDeep(option.series[0]), {
            name: '准时到达项',
            data: arrIntime,
            label: { color: colorList.green.color },
            itemStyle: { color: { colorStops: colorList.green.colorStops } }
          });

          option.series[2] = _.merge(_.cloneDeep(option.series[0]), {
            name: '未准时到达项',
            data: arrNotintime,
            label: { color: colorList.red.color },
            itemStyle: { color: { colorStops: colorList.red.colorStops } }
          });

          option.series[3] = _.merge(_.cloneDeep(option.series[0]), {
            name: '准时到达率',
            data: arrIntimeRate,
            type: 'line',
            symbolSize: 10,
            yAxisIndex: 1,
            smooth: true,
            label: { color: colorList.black.color, formatter: '{c}%' },
            lineStyle: { width: 3, color: colorList.black.color },
            itemStyle: { color: { colorStops: colorList.black.colorStops } }
          });

          chart.setOption(option);
          chart.on('click', (params) => {
            if (params.seriesName === '准时到达率') { return; }
            if (params.value == 0) { return; }
            this.detail.queryInfo.currentPage = 1;
            this.detail.title = `${params.name} 【${params.seriesName}】明细`;
            this.detail.dialogVisiable = true;
            this.detail.queryInfo.factoryname = params.name;
            this.detail.queryInfo.seriesName = params.seriesName;
            this.detail.queryInfo.title = `${params.name} 【${params.seriesName}】明细`;
            this.getChartDetail();
          })
        },
        async getChartDetail() {
          this.loading = true;
          this.loadingText = '数据加载中...';
          const { data: { data, meta, total } } = await axios({
            url: `${this.baseApi}?action=getChartDetail`,
            method: 'post',
            data: {
              type: 'getChartDetail',
              ...this.queryInfo,
              ...this.detail.queryInfo
            }
          })
          this.loading = false;
          if (meta.status === 500) { return this.$message.error(meta.msg); }
          this.detail.dataList = data;
          this.detail.total = total;
        },
        handleDetailCurrentChange(newPage) {
          this.detail.queryInfo.currentPage = newPage;
          this.getChartDetail();
        }
      },
      async mounted() {
        this.factoryList = await getFactory();
        this.tofactoryname = '热表厂';
        this.diaoDuYuanList = await getFactoryUsersByRoleName({ factoryname: this.queryInfo.tofactoryname, rolename: '调度员' });
        this.productfamilyList = await getProductFamily();

        const startOfYear = dayjs().startOf('year').format('YYYY-MM-DD')
        const endOfYear = dayjs().endOf('year').format('YYYY-MM-DD')
        const lastSaturday = dayjs().startOf('week').subtract(1, 'day').format('YYYY-MM-DD')
        const thisFriday = dayjs().startOf('week').add(5, 'day').format('YYYY-MM-DD')
        const lastMonday = dayjs().startOf('week').add(1, 'day').subtract(7, 'day').format('YYYY-MM-DD')
        const lastSunday = dayjs().startOf('week').format('YYYY-MM-DD')
        this.queryInfo.originalstartdate = [startOfYear, endOfYear] //批次开卡日期 默认本年
        this.queryInfo.plannedstartdate = [lastSaturday, thisFriday] // 计划发出日期，默认本周六 ~下周五
      },
      watch: { queryInfo: { handler() { this.queryInfo.currentPage = 1 }, deep: true } }
    })
  </script>
</body>

</html>